<template>
	<view class="">
		<view class="ptb24" :class="{'content':type==-1}">
			<view class="bgf p2432 br12">
				<view class="fs30 c2a7 fw600">订单信息</view>
				<view class="mt40 flex_x">
					<view class="fs28 c9 mr30">订单编号</view>
					<view class="fs28 c3">{{order_details.sn}}</view>
				</view>
				<view class="cut_line mtb24"></view>
				<view class=" flex_x">
					<view class="fs28 c9 mr30">用户昵称</view>
					<view class="fs28 c3">{{order_details.address.contact}}</view>
				</view>
				<view class="cut_line mtb24"></view>
				<view class=" flex_x">
					<view class="fs28 c9 mr30">用户电话</view>
					<view class="fs28 c3">{{order_details.address.telephone}}</view>
				</view>
			</view>
			<view class="bgf p2432 mt24 br12">
				<view class="fs30 c2a7 fw600">用户备注</view>
				<view class="mt40 p24 fs28 c3 text_a">{{order_details.content}}</view>
			</view>
			<view class="mt24 bgf p2432 br12">
				<view class="fs30 c2a7 fw600 mb40">商品信息</view>
				<goodsList :list="goods_list" :is_serve="true" :count='count'></goodsList>
			</view>
			<view class="bgf p2432 mt24 br12" v-if="type == 2 || type == 3">
				<view class="fs30 c2a7 fw600">取货员信息</view>
				<view class="mt40 flex_x fw500">
					<view class="fs28 c9 mr60">取货员</view>
					<view class="fs28 c3">张三</view>
				</view>
				<view class="cut_line mtb24"></view>
				<view class=" flex_x fw500">
					<view class="fs28 c9 mr30">联系方式</view>
					<view class="fs28 c3">18745612587</view>
				</view>
				<view class="cut_line mtb24"></view>
				<view class=" flex_x fw500">
					<view class="fs28 c9 mr30">负责区域</view>
					<view class="fs28 c3">武侯区</view>
				</view>
			</view>
			<view class="bgf p2432 mt24" v-if="type == 3">
				<view class="fs30 c2a7 fw600">入库信息</view>
				<view class="mt40 flex_x fw500">
					<view class="fs28 c9 mr60">入库员</view>
					<view class="fs28 c3">张三</view>
				</view>
				<view class="cut_line mtb24"></view>
				<view class=" flex_x fw500">
					<view class="fs28 c9 mr30">联系方式</view>
					<view class="fs28 c3">18745612587</view>
				</view>
				<view class="cut_line mtb24"></view>
				<view class=" flex_x fw500">
					<view class="fs28 c9 mr60">清洗点</view>
					<view class="fs28 c3">清洗点1号</view>
				</view>
			</view>
		</view>

		<view class="bgf box_s flex_c" v-if="type==-1">
			<view class="cf fs26 bg2a7 btn1 mtb10 flex_c" @click="confirmAllot">确认分配订单</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				id: '', //订单id
				order_details: '', //订单详情
				goods_list: [], //订单商品列表
				count: 0, //订单数量
				type: "-1", //-1扫码分配 0待投放 1待取货 2配送中 3已入库

				code: '', //扫码
			}
		},
		onLoad(options) {
			if (options.type) { //状态
				this.type = options.type
				uni.setNavigationBarTitle({ //修改导航栏文字
					title: options.type == -1 ? '扫码分配' : '订单详情'
				})
			}

			if (options.id) { //订单id
				this.id = options.id
				this.orderInfo()
			}

			if (options.code) { //扫码绑定订单
				this.code = options.code
			}
		},
		onShow() {

		},
		methods: {
			orderInfo() { //订单详情
				this.$api.orderInfo({
					id: this.id
				}).then(res => {
					if (res.code == 1) {
						res.data.goods.map(item => {
							item.goods = {
								id: item.goods_id,
								image_str: item.image_str,
								price: item.goods_price,
								title: item.goods_name,
							}
							item.num = item.goods_num
						})
						this.goods_list = res.data.goods
						this.count = res.data.total
						this.order_details = res.data
					}
				})
			},
			confirmAllot() { //确认分配订单
				if (this.type == -1) {
					this.$u.debounce(this.distribution, 500) //防抖
				} else if (this.type == 8) {

				}
			},
			distribution() { //扫码分配
				this.$api.distribution({
					sn: this.code,
					id: this.id
				}).then(res => {
					if (res.code == 1) {
						this.$toast.toast(res.msg, () => {
							uni.$emit('refresh')
							uni.navigateBack()
						})
					} else {
						uni.$u.toast(res.msg)
					}
				})
			},
			saoReturn() { //确认送回
				this.$api.saoReturn({
					sn: this.code,
					id: this.id
				}).then(res => {
					if (res.code == 1) {
						this.$toast.toast(res.msg, () => {
							uni.$emit('refresh')
							uni.navigateBack()
						})
					} else {
						uni.$u.toast(res.msg)
					}
				})
			},
			confirmReturn() { //确认归还
				this.$api.confirmReturn({
					sn: this.code,
					id: this.id
				}).then(res => {
					if (res.code == 1) {
						this.$toast.toast(res.msg, () => {
							uni.$emit('refresh')
							uni.navigateBack()
						})
					} else {
						uni.$u.toast(res.msg)
					}
				})
			},
		},
	}
</script>
<style lang="scss" scoped>
	.content {
		padding-bottom: calc(150upx + env(safe-area-inset-bottom));
	}

	.text_a {
		box-sizing: border-box;
		background: #f6f6f6;
		min-height: 168upx;
	}

	.box_s {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		box-shadow: 0px -1px 0px 0px #E6E6E6;
		padding-bottom: calc(env(safe-area-inset-bottom));

		.btn1 {
			width: 687upx;
			height: 80upx;
			border-radius: 40upx;
		}
	}
</style>
